<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #dd{
            width: 50px;
            height: 50px;
            background-color: aqua;
            position: absolute;
            top: 50px;
            left: 50px;
        }
    </style>
</head>
<body>
    <div id="dd">

    </div>
    <script>
        var dd=document.getElementById("dd")
        var isd=false
        var offX=0
        var offY=0
        dd.onmousedown=function(e){
            isd=true
            offX=e.offsetX
            offY=e.offsetY
        }
        dd.onmousemove=function(e){
           if(isd){
            dd.style.left=e.clientX-offX+"px"
            dd.style.top=e.clientY-offY+"px"
           }

        }
        dd.onmouseup=function(){
            isd=false
        }
    </script>
</body>
</html>